using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Edge.Business.Domain.Dictionaries;
using Edge.Common;
using Edge.Common.ComponentModel;
using Edge.Common.Services;
using Edge.Common.Utils;
using Edge.Business.Entities;


namespace Edge.Business.Domain
{
    [Serializable]
    public partial class PlaceHolder : BaseEntity<int>, IComparable
    {
        private string _name;
        private int _entityId;
        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public int EntityId
        {
            get { return _entityId; }
            set { _entityId = value; }
        }

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }

        public int CompareTo(object obj)
        {
            if (!(obj is PlaceHolder))
                throw new InvalidCastException("This object is not of type PlaceHolder");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((PlaceHolder)obj).Id);
                    break;
                case "Name":
                    relativeValue = (this.Name != null) ? this.Name.CompareTo(((PlaceHolder)obj).Name) : -1;
                    break;
                case "EntityId":
                    relativeValue = this.EntityId.CompareTo(((PlaceHolder)obj).EntityId);
                    break;
                default:
                    goto case "Id";
            }
            return relativeValue;
        }

        public override bool Equals(object obj)
        {
            if (this == obj) return true;
            PlaceHolder holder = obj as PlaceHolder;
            if (holder == null) return false;
            return Equals(_name, holder._name) && Equals(_entityId, holder._entityId);
        }
    }

    [Serializable]
    public partial class SpecialOfferHolderListProvider : IListProvider
    {
        public ICollection Get()
        {
            return CollectionsUtils.FindAll<PlaceHolder>(Locator.GetService<IDictionariesManager>().GetDictionary<PlaceHolder>(),
                                                         delegate(PlaceHolder obj)
                                                             {
                                                                 return obj.EntityId == 1001;
                                                             });
        }
    }

    [Serializable]
    public partial class BannerHolderListProvider : IListProvider
    {
        public ICollection Get()
        {
            return CollectionsUtils.FindAll<PlaceHolder>(Locator.GetService<IDictionariesManager>().GetDictionary<PlaceHolder>(),
                                                         delegate(PlaceHolder obj)
                                                             {
                                                                 return obj.EntityId == 1000;
                                                             });
        }
    }
}